home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------
- events.c
-
- THINK C "Set Project Type..." settings:
- code resource, type 'OAPn', ID 1000,
- custom header, preloaded and locked,
- file type 'rsrc', file creator 'RSED'.
- ------------------------------------------
- */
- #include <Traps.h>
- #include "defs.h"
-
- void main(void);
- void My_SystemEvent( void );
-
- /* -------- global variables ---------- */
- long Old_SystemEvent = NIL;
-
- void main(void)
- {
- long save_A4;
-
- asm {
- move.L A4, save_A4
- LEA main, A4
- }
-
- if (Old_SystemEvent == NIL)
- {
- Old_SystemEvent = GetToolTrapAddress(
- _SystemEvent );
- SetToolTrapAddress( (long)My_SystemEvent,
- _SystemEvent );
- }
-
- asm {
- move.L save_A4, A4
- }
- }
-
- /* ------------------------------------------
- My_SystemEvent This head patch watches
- events.
- ------------------------------------------
- */
- void My_SystemEvent( void )
- {
- EventRecord *evt;
- WindowPeek front;
- short res_index;
- Handle code_h;
- OAPe_proc Event_filter;
-
- asm {
- movem.L a0-a5/d0-d7, -(SP) ; save registers
- LEA main, A4 ; access to globals
- move.L 8(A6), evt ; copy event pointer
- }
-
- front = (WindowPeek) FrontWindow();
- if ( (front != NIL) &&
- (front->windowKind != 2) && front->visible &&
- front->hilited && front->goAwayFlag )
- {
- for (res_index = 1; ; ++res_index)
- {
- code_h = GetIndResource( 'OAPe', res_index );
- if (code_h == NIL)
- break;
- Event_filter = (OAPe_proc)
- StripAddress(*code_h);
- Event_filter( evt );
- }
- }
-
- asm {
- move.L (A6), -4(A6)
- move.L Old_SystemEvent, (A6)
- subQ #4, A6
- movem.L (SP)+, A0-A5/D0-D7
- }
- }
-